package com.example.controller;

import com.example.common.Result;
import com.example.model.dto.ProductQueryDTO;
import com.example.model.vo.PageResult;
import com.example.model.vo.ProductVO;
import com.example.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * 产品控制器
 */
@RestController
@RequestMapping("/api/v1/products")
public class ProductController {
    
    private static final Logger logger = LoggerFactory.getLogger(ProductController.class);
    
    private final ProductService productService;
    
    public ProductController(ProductService productService) {
        this.productService = productService;
    }
    
    /**
     * 获取产品列表
     */
    @GetMapping
    public Result<PageResult<ProductVO>> listProducts(ProductQueryDTO queryDTO) {
        logger.info("获取产品列表: {}", queryDTO);
        PageResult<ProductVO> pageResult = productService.listProducts(queryDTO);
        return Result.success(pageResult);
    }
    
    /**
     * 获取产品详情
     */
    @GetMapping("/{id}")
    public Result<ProductVO> getProductById(@PathVariable("id") Long id) {
        logger.info("获取产品详情: id={}", id);
        ProductVO product = productService.getProductById(id);
        return Result.success(product);
    }
} 